<%@ page language="java" import="java.util.*,com.xiaobin.system.util.*"
	pageEncoding="UTF-8"%>
<%@ include file="/base/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>${systemOption.systemTitle}</title>
<%@ include file="/base/head.jsp"%>	

 <script language="javascript" src="${ctx}/js/LodopFuncs.js"></script>
    <script type="text/javascript" charset="UTF-8">
    //分页查询
	function doQuery() {
		var queryParams = $('#mailList').datagrid('options').queryParams;
		queryParams.startSendTime = $('#startTime').datebox('getValue');
		queryParams.endSendTime = $('#endTime').datebox('getValue');
		queryParams.subject = $('#searchsubject').val();
		queryParams.fjrmc = $('#searchfjrmc').val();
		//重置当前页数为1
		resetDG('#mailList');
	}
	 //详情
	 function detail(){
	 	var row = $('#mailList').datagrid('getSelected');
	 	var subject='';
	 	if(row.subject !=''){
	 		subject = '邮件详情';
	 	}else{
	 		subject = '系统退信';
	 	}
	 	$('#tdFuJian').text('');
	 	$('#xqdlg').show();
	 	$('#xqdlg').dialog({
	 			title:subject,
	        	modal:true,
	        	maximizable:true,
	        	buttons: [{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
					$('#xqdlg').dialog('close');
					if(row.seen==1)
					{
					$('#mailList').datagrid('reload');
					}
				}
			}]
	 	});
 	//加载数据
    $.post("${ctx}/json/viewMail.action", {"id": row.id },
		function(data){
		if(data){
			var fjrmc = data.fjrmc;
			if(data.fromMail.indexOf('@zbshenai.com')!=-1){
				fjrmc +='['+data.fromMail+']';
			}
			$('#showFjrmc').html(fjrmc);
			$('#showsendTime').html(data.sendTime);
			if(data.fujian!=null && data.fujian !='' && data.fujian !='null'){
				$("#showFujian").show();
				var fujianName = data.fujianName;
				var fujian = data.fujian;
				var f ="";
				if(null != fujianName){
					f = fujianName.split(',');
				}
				var fname = fujian.split(',');
				var td='';
				for(var i = 0;i<f.length;i++){
					td+="<div><a id='showfujianId' href='#' onclick='downFujian(\""+fname[i]+"\","+row.id+")' style='color:blue;'>"+f[i]+"</a></div>";
				}
				$('#tdFuJian').append(td);
				$('#fujianSpan').html(data.fujian);
			}else{
				$("#showFujian").hide();
			}
			$('#showSubject').html(data.subject);
			$('#contentId').html(data.content);
			if(data.huizhi==2){//需要回执
				$('#huizhiDiv').show();
	 			$('#huizhiDiv').dialog({
	 				title:'提示',
			        modal:true,
			        closable:false,
			        buttons: [{
					text:'发送',
					iconCls:'icon-ok',
					handler:function(){
						$.post("${ctx}/json/huizhiMail.action", {"id": row.id },
						function(data){
							if(data){
								$.messager.alert('友情提示','回执发送成功','info');
							}else{
								$.messager.alert('友情提示','回执发送失败','error');
							}
						},"json");
						$('#huizhiDiv').dialog('close');
					}},{
							text:'不发送',
							iconCls:'icon-cancel',
							handler:function(){
								$.post("${ctx}/json/updatehuizhiMail.action", {"id": row.id },
									function(data){
										
									},"json");
								$('#huizhiDiv').dialog('close');
							}
						}]
	 				});
			}
		}else{
			$.messager.alert('友情提示','加载失败','error');
		}
	}, "json");
    $('#mailList').datagrid('reload');
 }
 	function formatStatus(val,row){
		if(row.seen==1){
			return '<img alt="新邮件" src="${ctx }/images/icon/16/email.png">';
		}else{
			return '<img alt="已读邮件" src="${ctx }/images/icon/16/email_open.png">';
		}
	}
	/**
		附件下载
	*/
	function downFujian(fujian,id){
		 window.location.href='${ctx}/zhgl/downFujian.action?fujian='+encodeURI(encodeURI(fujian));
	}
	
	//回复
	function reply(){
		var row = $('#mailList').datagrid('getSelected');
		if(!row){
			$.messager.alert('友情提示', '请选择行', 'error');
			return;
		}
		var url = "${ctx}/zhgl/replyMail.action?id="+row.id+"&type="+2;
		$('#replyIframe').attr("src",url);
		$('#replyWin').show();
		$('#replyWin').dialog({
			title:'写信',
			modal:true,
			fit:true,
	    	maximized:true
		});
	}
	
	/*
	 关闭回复窗口
	*/
	function closeReplyWin(){
		$('#replyWin').dialog('close');
	}
	
	/**
		删除邮件
	**/
	
	function removeMail(){
		var row = $('#mailList').datagrid('getSelected');
		if(!row){
			$.messager.alert('友情提示', '请选择要删除的行', 'error');
			return;
		}
		$.messager.confirm('友情提示', '将删除，确定么？', function(r) {
			if (r) {
				$.post("${ctx}/json/delMail.action", {
					"id" : row.id
				}, function(data) {
					if (data) {
						$.messager.alert('友情提示', '删除成功', 'info');
						resetDG('#mailList');
					} else {
						$.messager.alert('友情提示', '删除失败', 'error');
					}
				}, "json");
			}
		});
	}
	
	/**
		转发
	**/
	function forward(){
		var row = $('#mailList').datagrid('getSelected');
		if(!row){
			$.messager.alert('友情提示', '请选择行', 'error');
			return;
		}
		var url = "${ctx}/zhgl/replyMail.action?id="+row.id+"&type="+3;
		$('#replyIframe').attr("src",url);
		$('#replyWin').show();
		$('#replyWin').dialog({
			title:'写信',
			modal:true,
	    	maximized:true
		});
	}
   
   function formatterB(val,row){
	   	if(row.seen==1){
			return '<B><font color=red>'+val+'</font></B>';
		}else{
			return val;
		}
   }
	/**
		滚动条
	*/
	function showProcess(isShow, title, msg) {

         if (!isShow) {
            $.messager.progress('close');
            return;
        }
        var win = $.messager.progress({
            title: title,
            msg: msg,
            text:''
        });

   }
	</script>
  </head>
  
  <body>
<!--         主窗口   	 -->
  	  <table id="mailList" class="easyui-datagrid" style="height:250px" data-options="
  	  									fit:true,
	    								rownumbers:true,
										singleSelect:true,
										striped:true,
										fitColumns:true,
										border:false,
										toolbar:'#tb',
										pagination:true,
										pageSize:20,
										nowrap:true,
										url:'${ctx}/json/listReceiveMail.action',
										onDblClickRow:detail">
			<thead>
				<tr>
					<th data-options="field:'ck',checkbox:true"></th>
					<th data-options="field:'seen',align:'center',formatter:formatStatus" width="50px"></th>
					<th data-options="field:'fjrmc',align:'center',formatter:formatterB" width="150px"><strong>发件人</strong></th>
					<th data-options="field:'subject',align:'left',formatter:formatterB" width="500px"><strong>主题</strong></th>
					<th data-options="field:'sendTime',align:'center',formatter:formatterB" width="150px"><strong>发件时间</strong></th>
					<th data-options="field:'id',hidden:true"></th>
				</tr>
			</thead>
		</table>
<!--		 Datagrid工具栏 -->
		<div id="tb">
			<table width="100%" cellpadding="0" cellspacing="0">
				<tr>
			   		<td class="toolDiv">
			   			<a href="javascript:void(0)" onclick="reply();" class="easyui-linkbutton" data-options="iconCls:'icon-email-edit',plain:true" style="float:left;">回复</a><div class="datagrid-btn-separator"> </div>
			   			  <a href="javascript:void(0)" onclick="forward();" class="easyui-linkbutton" data-options="iconCls:'icon-email-transfer',plain:true" style="float:left;">转发</a><div class="datagrid-btn-separator"> </div>
			  			<a href="javascript:void(0)" onclick="removeMail();" class="easyui-linkbutton" data-options="iconCls:'icon-email-delete',plain:true" style="float:left;">删除</a>
					</td>
				</tr>
				<tr>
					<td class="serchDiv">
					    发件人：<input id="searchfjrmc" class="easyui-validatebox" type="text"  style="width:200px">
						&nbsp;&nbsp; 
						主题：<input id="searchsubject" class="easyui-validatebox" type="text"  style="width:200px">
						&nbsp;&nbsp; 发送时间：
						<input id="startTime" class="easyui-datebox" />至<input id="endTime" class="easyui-datebox"/>
						&nbsp;&nbsp;<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" 
										onclick="doQuery()">查询</a>
					</td>
				</tr>
			</table>
		</div>
<!--		 详情窗口     -->
		<div id="xqdlg" style="width:750px;height:400px;overflow-x:hidden;overflow-y:auto;display: none">
				<table  class="dlgtb" width="100%" cellpadding=0 cellspacing=0 style="overflow-x:hidden;overflow-y:auto;">
					<tr height="30px" >
						<td class="lbl" width="8%">发件人</td>
						<td width="92%"><span id="showFjrmc"></span></td>
					</tr>
					<tr height="30px">
						<td class="lbl">时间</td>
						<td><span id="showsendTime"></span></td>
					</tr>
					<tr height="30px" >
						<td class="lbl" width="8%">主题</td>
						<td width="92%"><span id="showSubject"></span></td>
					</tr>
					<tr id="showFujian" style="display: none"  height="30px">
						<td class="lbl">附件</td>
						<td id="tdFuJian"></td>
					</tr>
					<tr>
						<td colspan="2" valign="top" id="contentId" style="border: 0px;">
						</td>
					</tr>
				</table>
		</div>
		<div id="replyWin" style="width:750px;overflow-x:hidden;overflow-y:auto;display: none">
			<iframe width="100%" height="99%" frameborder="0" align="top" 
    			scrolling="yes" style="margin-left: 0px;margin-top: 0px;" id="replyIframe">
    		</iframe>
		</div>
		<div id="huizhiDiv" style="width:300px;overflow-x:hidden;overflow-y:auto;display: none;height: 130px">
			<div style="margin-top: 20px"><center>发件人希望得到您的回执，是否发送？</center></div>
		</div>
  </body>
</html>
